package com.alex.jbpm.apply.task;

import org.jbpm.context.exe.ContextInstance;
import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.taskmgmt.def.AssignmentHandler;
import org.jbpm.taskmgmt.exe.Assignable;

public class ApplyProcessTask implements AssignmentHandler {

	private static final long serialVersionUID = 1575730952153658545L;

	public void assign(Assignable assign, ExecutionContext context) throws Exception {
		ContextInstance contextInstance = context.getContextInstance();
		
		String actorLevel = null;
		//获取申请单对应的行政区划信息，并根据行政区划设置操作用户级别
		/*if(contextInstance.getVariable("actorLevel") != null){
			actorLevel =  contextInstance.getVariable("actorLevel").toString();
		}else {*/
			String nodeName = contextInstance.getProcessInstance().getRootToken().getNode().getName();
			if(nodeName.indexOf("县级") != -1){
				actorLevel = "xian";
			}else if(nodeName.indexOf("市级") != -1){
				actorLevel = "shi";
			}else if(nodeName.indexOf("省级") != -1){
				actorLevel = "sheng";
			}else if(nodeName.indexOf("中央") != -1){
				actorLevel = "department";
			}
			if(contextInstance.getVariable("actorLevel") == null){
				contextInstance.createVariable("actorLevel", actorLevel);
			}else {
				contextInstance.setVariable("actorLevel", actorLevel);
			}
//		}
		assign.setActorId(actorLevel);
		
		
		System.out.println("进行公文：".concat(contextInstance.getVariable("documentId").toString()).concat("，【").concat(actorLevel).concat("】 任务分配..."));
	}

}
